package com.leather.market.controller;

import com.google.common.collect.Maps;
import com.leather.common.entity.GoodsType;
import com.leather.common.result.Result;
import com.leather.market.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;


    @GetMapping("/goodstypeindex")
    public Object goodsTypeIndex() {
        Map<String, Object> maps = Maps.newHashMap();
        List<GoodsType> list = goodsTypeService.list();
        maps.put("total", list.size());
        maps.put("rows", list);
        return maps;
    }

    @PostMapping("addgoodstype")
    public Result addGoodsType(@RequestBody GoodsType goodsType) {
        return goodsTypeService.addGoodsType(goodsType);
    }

    @GetMapping("list")
    public Result list() {
        return Result.success(goodsTypeService.list());
    }
}
